home *** CD-ROM | disk | FTP | other *** search
/ Aminet 15 / Aminet 15 - Nov 1996.iso / Aminet / util / moni / restracker.lha / restracker / FreeResource.a next >
Encoding:
Text File  |  1996-09-11  |  2.8 KB  |  117 lines

  1. ;***********************************************************************
  2. ;* FreeResource.a                                                      *
  3. ;* ©1996 M.Bethke                                                      *
  4. ;* Used in the rtFreeResources program and to show use of rt_ResList   *
  5. ;***********************************************************************
  6.  
  7.  
  8.     include "exec/lists.i"
  9.  
  10. LIBCALL MACRO
  11.     jsr    _LVO\1(a6)
  12.     ENDM
  13.  
  14.  
  15.     STRUCTURE RESLIST,MLH_SIZE
  16.     WORD    RL_ALLOC    ;allocation function offset
  17.     WORD    RL_FREE    ;deallocation function offset
  18.     CPTR    RL_LIB    ;library name for these offsets
  19.     APTR    RL_POOL    ;memory pool for nodes
  20.     WORD    RL_IDOFFSET    ;struct offset for resource description
  21.     BYTE    RL_FREEREG    ;register for deallocation function
  22.     BYTE    PAD    ;pad to word-alignment
  23.     LABEL    RL_SIZE
  24.  
  25.  
  26.  
  27.     XDEF _FreeResource
  28.  
  29. _LVOOpenLibrary        equ -552
  30. _LVOCloseLibrary    equ -414
  31.  
  32.     SECTION FreeResoure,CODE
  33.  
  34.  
  35. ;******************************************************************
  36. ;Inputs: a3: Pointer to resource
  37. ;        a4: Pointer to resourcelist
  38. ;Output: d0: Success
  39. ;******************************************************************
  40. _FreeResource:
  41.     movem.l    d1-d7/a0-a2/a5-a6,-(sp)
  42.     move.l    4.w,a6
  43.     move.l    RL_LIB(a4),a1        ;get library name
  44.     move.l    #0,d0        ;we *do* have the correct version :)
  45.     LIBCALL    OpenLibrary        ;open specified library
  46.     tst.l    d0
  47.     beq.s    NoLibrary        ;exit if failed
  48.     pea    LibcallDone(pc)        ;push address to continue at after libcall
  49.     move.l    d0,-(sp)        ;push libbase again for the actual call
  50.     move.l    d0,a6        ;for later libcall
  51.  
  52.     move.w    RL_FREE(a4),d1        ;get free offset
  53.     ext.l    d1
  54.     add.l    d1,(sp)        ;add to librarybase for jump destination
  55.     pea    DoLibJump(pc)        ;push return address for jumptable
  56.     moveq    #0,d1
  57.     move.b    RL_FREEREG(a4),d1    ;get register code for free()
  58.     lea    RegJumps(pc),a0        ;load jumptable start
  59.     lsl.w    #2,d1        ;extend to long offset
  60.     move.l    0(a0,d1.w),a0        ;retrieve jump address
  61.     jmp    (a0)        ;load correct register
  62. DoLibJump:                ;this is the next return address on stack!
  63.     rts            ;pops LibBase+LVO fromstack and jumps there
  64. LibcallDone:                ;the library's final rts gets us here
  65.     move.w    #-1,-(sp)        ;returncode=TRUE
  66. CloseLib:
  67.     move.l    a6,a1
  68.     move.l    4.w,a6
  69.     LIBCALL    CloseLibrary    
  70.     moveq    #1,d0
  71. Finish:
  72.     move.w    (sp)+,d0
  73.     ext.l    d0
  74.     movem.l    (sp)+,d1-d7/a0-a2/a5-a6
  75.     rts
  76. NoLibrary:
  77.     clr.w    -(sp)        ;returncode=FALSE
  78.     bra.s    Finish
  79.  
  80.  
  81. UseD0:    move.l    a3,d0
  82.     rts
  83. UseD1:    move.l    a3,d1
  84.     rts
  85. UseD2:    move.l    a3,d2
  86.     rts
  87. UseD3:    move.l    a3,d3
  88.     rts
  89. UseD4:    move.l    a3,d4
  90.     rts
  91. UseD5:    move.l    a3,d5
  92.     rts
  93. UseD6:    move.l    a3,d6
  94.     rts
  95. UseD7:    move.l    a3,d7
  96.     rts
  97. UseA0:    move.l    a3,a0
  98.     rts
  99. UseA1:    move.l    a3,a1
  100.     rts
  101. UseA2:    move.l    a3,a2
  102.     rts
  103. UseA3:    rts        ;no need to move anything :-)
  104. UseA4:    move.l    a3,a4
  105.     rts
  106. UseA5:    move.l    a3,a5
  107. UseA6:
  108. UseA7:    lea    12(sp),sp    ;should never happen!
  109.     clr.w    -(sp)    ;returncode=FALSE
  110.     bra.s    CloseLib
  111.  
  112.  
  113. RegJumps:    dc.l    UseD0,UseD1,UseD2,UseD3,UseD4,UseD5,UseD6,UseD7
  114.     dc.l    UseA0,UseA1,UseA2,UseA3,UseA4,UseA5,UseA6,UseA7
  115.  
  116.     END
  117.